package com.example.administrator.myleb.Brother;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.administrator.myleb.R;

import java.util.List;

/**
 * Created by Administrator on 2017/2/17.
 */

public class MyAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater mInflater;
    private List<Content> mDatas;
    public MyAdapter(Context context, List<Content> data) {
        this.context = context;
        mInflater = LayoutInflater.from(context);
        mDatas=data;
    }
    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder=new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_main, null);
            holder.mTitle = (TextView) convertView.findViewById(R.id.title);
            holder.mDesc = (TextView) convertView.findViewById(R.id.desc);
            holder.mTime = (TextView) convertView.findViewById(R.id.time );
            holder.mPhone = (TextView) convertView.findViewById(R.id.phone);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        Content item = mDatas.get(position);
        holder.mTitle.setText(item.title);
        holder.mDesc.setText(item.desc);
        holder.mTime.setText(item.time);
        holder.mPhone.setText(item.phone);
        return convertView;
    }
   class ViewHolder{
        TextView mTitle;
        TextView mDesc;
        TextView mTime;
        TextView mPhone;
    }
}
